package tj.eskhata.pos.dao.hibernate;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.springframework.asm.Type;

import tj.eskhata.pos.common.SBRate;
import tj.eskhata.pos.dao.SprvalDao;
import tj.eskhata.pos.domain.Certificate;
import tj.eskhata.pos.domain.Client;
import tj.eskhata.pos.domain.Sprval;

public class SprvalDaoImpl extends AbstractHibernateDaoImpl<Sprval>
    implements SprvalDao {

  public SprvalDaoImpl() {
    super(Sprval.class);
  }
  
  public SBRate GetSBRate(Long ftMoney, Date onDate) {
	  Connection con=getSession().connection();	  
	  SBRate	res=new SBRate();
	  ResultSet rs;
	  Certificate cert= new Certificate();
	  Long i=0L;
	  
	  try {
		CallableStatement clst= con.prepareCall("begin SPRVAL#.GETSBRATE(?,?,?,?,?); end;");
		
		clst.setLong	(1, ftMoney);
		java.sql.Date dateSql;
        dateSql=null;
        if(onDate!=null)
        	dateSql= new java.sql.Date(onDate.getTime());
        clst.setDate	(2, dateSql);
		
		clst.registerOutParameter(3, java.sql.Types.NUMERIC);
		clst.registerOutParameter(4, java.sql.Types.NUMERIC);
		clst.registerOutParameter(5, java.sql.Types.NUMERIC);
		clst.execute();//executeQuery();
		res.ftRateBay=clst.getBigDecimal(3);
		res.ftRateSale=clst.getBigDecimal(4);
		res.ftUnit=clst.getLong(5);		
		        
	  } catch (SQLException e) {
		e.printStackTrace();
	  }
	  /*Query criteria=getSession().createQuery("from Client c where c.id=:id ").setCacheable(false);      
      criteria.setLong("id", i);
      Client r=(Client)criteria.list().get(0);
	  */
	  
	  return res;
  }

}
